/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ifs.RnD.svnRead;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 *
 * @author anaklk
 */
public class Node {

    private String data;
    private List<Node> children;
    private Node parent;
    private String svnUrl, author, type;
    private long revision;
    private Date entryDate;
    private boolean hasExternals;

    /**
     * Convenience constructor to create a Node<T> with an instance of T.
     * @param data an instance of T.
     * @param type 
     * @param svnUrl
     * @param author 
     * @param revision 
     * @param external
     * @param date 
     * @param parent  
     */
    public Node(String data, String type, String svnUrl, String author, long revision, Date date, Node parent, boolean external) {
        this.data = data;
        this.svnUrl = svnUrl;
        this.parent = parent;
        this.entryDate = date;
        this.revision = revision;
        this.author = author;
        this.type = type;
        this.hasExternals = external;
    }

    /**
     * 
     * @param data
     * @param type
     * @param svnUrl
     * @param parent
     */
    public Node(String data, String type, String svnUrl, Node parent) {
        this.data = data;
        this.svnUrl = svnUrl;
        this.parent = parent;
        this.type = type;
    }

    Node(String exName, String type, String extPath, Node localRoot, boolean hasExt) {
        this.data = exName;
        this.type = type;
        this.svnUrl = extPath;
        this.parent = localRoot;
        this.hasExternals = hasExt;
    }

    /**
     * Return the children of Node<T>. The Tree<T> is represented by a single
     * root Node<T> whose children are represented by a List<Node<T>>. Each of
     * these Node<T> elements in the List can have children. The getChildren()
     * method will return the children of a Node<T>.
     * @return the children of Node<T>
     */
    public List<Node> getChildren() {
        if (this.children == null) {
            return new ArrayList<Node>();
        }
        return this.children;
    }

    /**
     * Sets the children of a Node<T> object. See docs for getChildren() for
     * more information.
     * @param children the List<Node<T>> to set.
     */
    public void setChildrenList(List<Node> children) {
        this.children = children;
    }

    /**
     * Returns the number of immediate children of this Node<T>.
     * @return the number of immediate children.
     */
    public int getNumberOfChildren() {
        if (children == null) {
            return 0;
        }
        return children.size();
    }

    /**
     * Adds a child to the list of children for this Node<T>. The addition of
     * the first child will create a new List<Node<T>>.
     * @param child a Node<T> object to set.
     */
    public void addChildToList(Node child) {
        if (children == null) {
            children = new ArrayList<Node>();
        }
        children.add(child);
    }

    /**
     * Inserts a Node<T> at the specified position in the child list. Will     * throw an ArrayIndexOutOfBoundsException if the index does not exist.
     * @param index the position to insert at.
     * @param child the Node<T> object to insert.
     * @throws IndexOutOfBoundsException if thrown.
     */
    public void insertChildAt(int index, Node child) throws IndexOutOfBoundsException {
        if (index == getNumberOfChildren()) {
            // this is really an append
            addChildToList(child);
            return;
        } else {
            children.get(index); //just to throw the exception, and stop here
            children.add(index, child);
        }
    }

    /**
     * Remove the Node<T> element at index index of the List<Node<T>>.
     * @param index the index of the element to delete.
     * @throws IndexOutOfBoundsException if thrown.
     */
    public void removeChildAt(int index) throws IndexOutOfBoundsException {
        children.remove(index);
    }

    /**
     * Return the string value of the corresponding Node object
     * @return String value of Node
     */
    public String getData() {
        return this.data;
    }

    /**
     * Return the boolean value of the hasExternal variable of Node object
     * @return boolean value of hasExternal
     */
    public boolean hasExternals() {
        return hasExternals;
    }

    /**
     * Return the current URL as a string
     * @return String value of the URL
     */
    public String getSvnURL() {
        return this.svnUrl;
    }

    /**
     * Return the author file or directory of the node
     * @return String value of the author of that node
     */
    public String getAuthor() {
        return this.author;
    }

    /**
     * Return the current revision value of the node object
     * @return String value of the revision of the node
     */
    public long getRevision() {
        return this.revision;
    }

    /**
     * Return the last modified date of the directory or file in the repository
     * @return date object correspond to the last modified date
     */
    public Date getDate() {
        return this.entryDate;
    }

    /**
     * Return the node type of the corresponding node (ROOT, DIR, FILE)
     * @return String value of the type
     */
    public String getType() {
        return this.type;
    }

    /**
     * returns the parent directory
     * @return
     */
    public Node getParent() {
        return this.parent;
    }

    /**
     *
     * @param data 
     */
    public void setData(String data) {
        this.data = data;
    }

    /**
     *set the type of the Node (ROOT, DIR, FILE)
     * @param type 
     */
    public void setType(String type) {
        this.type = type;
    }

    /**
     * @param url 
     */
    public void setSvnURL(String url) {
        this.svnUrl = url;
    }

    /**
     * @param pnt 
     */
    public void setParent(Node pnt) {
        this.parent = pnt;
    }

    
    /**
     * @return
     */
    @Override
    public String toString() {
        return (this.getData() + " - " + this.getSvnURL());
    }

   
}
